package logic

import (
	"context"
	"house123/C/srv/model/mysql"

	"house123/C/srv/house"
	"house123/C/srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *house.GoodsListRequest) (*house.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	g := []mysql.Goods{}
	mysql.DB.Order("like_house desc").Find(&g)

	var good []*house.GoodsList
	for _, i := range g {
		lists := house.GoodsList{
			Title:     i.Title,
			Cover:     i.Cover,
			Price:     float32(i.Price),
			LikeHouse: i.LikeHouse,
			Status:    i.Status,
		}
		good = append(good, &lists)
	}

	return &house.GoodsListResponse{List: good}, nil
}
